package com.nulstudio.sppm.controller;

import com.nulstudio.sppm.NulHitSppm16BackApplication;
import com.nulstudio.sppm.entity.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@CrossOrigin(origins = "*")
@RequestMapping("/service/user")
public class PersonalInformationController {

    private String name = "NULL";

    @RequestMapping("/userInfo")
    @ResponseBody
    public NulHitSppm16BackApplication.Result<PersonalInformation> userInfo() {
        final PersonalInformation personalInformation =
                new PersonalInformation(1, name, "nullsty", "male", "Administrator");
        return new NulHitSppm16BackApplication.Result<>(personalInformation);
    }

    @RequestMapping("/updateName")
    @ResponseBody
    public NulHitSppm16BackApplication.Result<PersonalName> updateName(@RequestBody NulHitSppm16BackApplication.Request<NulHitSppm16BackApplication.UpdateNameRequest> request) {
        name = request.getRequest().getName();
        return new NulHitSppm16BackApplication.Result<>(new PersonalName(name));
        //return new Result<>(new PersonalName(request.getRequest().getName()));
    }


}
